﻿--lua script
--FirstRecharge
--#include "data\config\recharge\FirstRechargeConfig.lua" once
--#include "data\config\recharge\RechargeConfig.lua" once

--发送领取状态
function SendFirstRechargeGetState(sysarg)
  local sVar = Actor.getStaticVar(sysarg)
  if not sVar.firstRechargeState then
    sVar.firstRechargeState = 0
  end
  local netPack = DataPack.allocPacket(sysarg, LogicCmd.miscSys.sysId, LogicCmd.miscSys.sub.sGetFirstCharge) 
  if not netPack then return end
  DataPack.writeByte(netPack, sVar.firstRechargeState)
  DataPack.flush(netPack)
end

--更新领取状态
function UpdateFirstRechargeGetState(sysarg)
  local sVar = Actor.getStaticVar(sysarg)
  if not sVar.firstRechargeState or sVar.firstRechargeState == 0 then
    sVar.firstRechargeState = 1
    TitleEventTrigger(sysarg, HeadTitleEvent.Recharge, 1)
  end
  SendFirstRechargeGetState(sysarg)
end

--领取
function GetFirstRechargeAward(sysarg)
  local sVar = Actor.getStaticVar(sysarg)
  if sVar.firstRechargeState and sVar.firstRechargeState == 1 then
    if CheckBagGridForAwardsEx(sysarg, FirstRechargeCfg.firstAward) == 0 then
      sVar.firstRechargeState = 2
      local logId = 1013
      local logStr = Lang.LogTips.l00173
      GiveCommonAwardEx(sysarg, FirstRechargeCfg.firstAward, logId, logStr)
      SendFirstRechargeGetState(sysarg)
      local msg = string.format(Lang.ScriptTips.FirstRecharge001, Actor.getName(sysarg))
      System.broadcastTipmsgLimitLev(msg, ttScreenCenter + ttChatWindow, FirstRechargeCfg.openLevel)
    else
      Actor.sendTipmsg(sysarg, Lang.ScriptTips.COM0015, ttFlyTip)
    end
  end
end


